// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import "./js/mapsettingdb.js" as DataBase

Item {
    width: 0
    height: 0

    Component.onCompleted:
    {
        DataBase.createdb();

        setting_gps_status = DataBase.get_setting_gps_status();
        console.log(setting_gps_status);
        setting_gps_follow_me = DataBase.get_setting_gps_follow_me();
        console.log(setting_gps_follow_me);
        setting_gps_update_interval = DataBase.get_setting_gps_update_interval();
        console.log(setting_gps_update_interval);
        setting_gps_follow_interval = DataBase.get_setting_gps_follow_interval();
        console.log(setting_gps_follow_interval);
        setting_gps_last_lat = DataBase.get_setting_gps_last_lat();
        setting_gps_last_lon = DataBase.get_setting_gps_last_lon();
        setting_sogou_last_lat = DataBase.get_setting_sogou_last_lat();
        console.log(setting_sogou_last_lat);
        setting_sogou_last_lon = DataBase.get_setting_sogou_last_lon();
        setting_sogou_map_level = DataBase.get_setting_sogou_map_level();
        console.log(setting_sogou_map_level);
        setting_style = DataBase.get_setting_style();
    }

    property bool setting_gps_status: true
    onSetting_gps_statusChanged:
    {
        positionSource.active = setting_gps_status;
        DataBase.set_setting_gps_status(setting_gps_status);
    }

    property bool setting_gps_follow_me: false
    onSetting_gps_follow_meChanged:
    {
        timerUpdatepos.running = setting_gps_follow_me;
        DataBase.set_setting_gps_follow_me(setting_gps_follow_me);
    }

    property int setting_gps_update_interval: 10
    onSetting_gps_update_intervalChanged:
    {
        positionSource.updateInterval = setting_gps_update_interval * 1000;
        DataBase.set_setting_gps_update_interval(setting_gps_update_interval);
    }

    property int setting_gps_follow_interval: 10
    onSetting_gps_follow_intervalChanged:
    {
        timerUpdatepos.interval = setting_gps_follow_interval * 1000;
        DataBase.set_setting_gps_follow_interval(setting_gps_follow_interval);
    }

    property string setting_gps_last_lat: ""
    onSetting_gps_last_latChanged:
    {
        DataBase.set_setting_gps_last_lat(setting_gps_last_lat);
    }

    property string setting_gps_last_lon: ""
    onSetting_gps_last_lonChanged:
    {
        DataBase.set_setting_gps_last_lon(setting_gps_last_lon);
    }

    property string setting_sogou_last_lat: ""
    onSetting_sogou_last_latChanged:
    {
        DataBase.set_setting_sogou_last_lat(setting_sogou_last_lat);
    }

    property string setting_sogou_last_lon: ""
    onSetting_sogou_last_lonChanged:
    {
        DataBase.set_setting_sogou_last_lon(setting_sogou_last_lon);
    }

    property int setting_sogou_map_level: 10
    onSetting_sogou_map_levelChanged:
    {
        DataBase.set_setting_sogou_map_level(setting_sogou_map_level);
    }

    property int notification_show_time: 5000

    property string setting_style: "darkblue"
    onSetting_styleChanged:
    {
        DataBase.set_setting_style(setting_style);
    }

    property string bus_start_text: ""
    property string bus_start_lonlat: ""
    property string bus_end_text: ""
    property string bus_end_lonlat: ""
    property string bus_avoid: "0"
    property string bus_tactic: "8"
    property string bus_maxResultCount: "10"
    property string bus_maxDist: ""

    property variant bus_in_array: []
    property variant bus_out_array: []
    property variant bus_inxy_array: []
    property variant bus_outxy_array: []
    property variant bus_linename_array: []

    function get_search_model()
    {
        return search_result_model;
    }

    function get_route_model()
    {
        return route_result_model;
    }

    function set_route_model(bus_time, bus_walkdist, bus_line_num, bus_line_names)
    {
        route_result_model.append(
                    {
                        "bus_time": bus_time,
                        "bus_walkdist": bus_walkdist,
                        "bus_line_num": bus_line_num,
                        "bus_line_names": bus_line_names
                    }
                    );
    }

    function clear_route_model()
    {
        route_result_model.clear();
    }

    ListModel
    {
        id: search_result_model
    }

    ListModel
    {
        id: route_result_model
    }
}
